package com.itheima.service.impl;

import com.itheima.mapper.AccountMapper;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


//注解的事务

//存入ioc
@Service

//isolation设置事务的隔离级别  propagation 设置事务的传播行为
//@Transactional(readOnly = false,isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)
@Transactional  //可以在类上面配置 也可以在方法上配置
public class AccountServiceImpl  implements AccountService {
    //创建数据层对象 从spring ioc容器中取值给accountMapper
    @Autowired
    private AccountMapper accountMapper;



//    @Transactional
    public void transfer(String sname, String tname, Double money) {

        //转入  tname转出钱的人
        accountMapper.inUpdate(tname, money);
        //制造异常
//        int i = 1 / 0;

        //转出 sname 转出钱的人
        accountMapper.outUpdate(sname,money);
    }
}
